﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThouShaltNotBrick.Models;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using Microsoft.Xna.Framework.Content.Pipeline;
using ThouShaltNotBrick.PipelineExtension.Readers;

namespace ThouShaltNotBrick.PipelineExtension
{
    [ContentTypeWriter]
    public sealed class BrickStatesContentTypeWriter : ContentTypeWriter<BrickStatesData>
    {
        #region Overriden Methods
        protected override void Write(ContentWriter pOutput, BrickStatesData pValue)
        {
            // NUMBER OF BRICK STATES (int)
            //   NAME (string)
            //   IS_INDESTRUCTIBLE (bool)
            //   TEXTURE_FILE_NAME (string)

            List<BrickStateData> brickStateList = pValue.GetBrickStates();
            pOutput.Write(brickStateList.Count);
            foreach (BrickStateData brickState in brickStateList)
            {
                pOutput.Write(brickState.Name);
                pOutput.Write(brickState.IsIndestructible);
                pOutput.Write(brickState.TextureFileName);
            }
        }

        public override string GetRuntimeReader(TargetPlatform pTargetPlatform)
        {
            return typeof(BrickStatesContentTypeReader).AssemblyQualifiedName;
        }

        public override string GetRuntimeType(TargetPlatform pTargetPlatform)
        {
            return typeof(BrickStatesData).AssemblyQualifiedName;
        }
        #endregion
    }
}